{% extends 'base.html' %}

{% block title %}工序管理{% endblock %}

{% block content %}
<div class="container">
    <h1 class="mb-4">工序管理</h1>
    
    <!-- Excel导入表单 -->
    <div class="card mb-4">
        <div class="card-header">
            <h5 class="card-title mb-0">批量导入工序</h5>
        </div>
        <div class="card-body">
            <form action="{{ url_for('excel_import.import_processes') }}" method="post" enctype="multipart/form-data">
                <div class="mb-3">
                    <label for="file" class="form-label">选择Excel文件</label>
                    <input type="file" class="form-control" id="file" name="file" accept=".xlsx,.xls" required>
                    <div class="form-text">支持的文件格式：.xlsx, .xls</div>
                </div>
                <button type="submit" class="btn btn-primary">导入数据</button>
            </form>
        </div>
    </div>

    <!-- 工序列表 -->
    <div class="card">
        <div class="card-header d-flex justify-content-between align-items-center">
            <h5 class="card-title mb-0">工序列表</h5>
            <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addProcessModal">新增工序</button>
        </div>
        <div class="card-body">
            {% with messages = get_flashed_messages() %}
                {% if messages %}
                    {% for message in messages %}
                        <div class="alert alert-info">{{ message }}</div>
                    {% endfor %}
                {% endif %}
            {% endwith %}
            
            {% if processes %}
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>名称</th>
                            <th>计价单位</th>
                            <th>单价</th>
                            <th>工序描述</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for process in processes %}
                        <tr>
                            <td>{{ process.id }}</td>
                            <td>{{ process.name }}</td>
                            <td>{{ process.unit }}</td>
                            <td>{{ "%.2f"|format(process.price) }}</td>
                            <td>{{ process.description }}</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            {% else %}
            <p class="text-muted">暂无工序数据</p>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}

<!-- 添加工序模态框 -->
<div class="modal fade" id="addProcessModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">新增工序</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body">
                <form id="addProcessForm" action="{{ url_for('add_process') }}" method="post">
                    <div class="mb-3">
                        <label for="name" class="form-label">工序名称</label>
                        <input type="text" class="form-control" id="name" name="name" required>
                    </div>
                    <div class="mb-3">
                        <label for="unit" class="form-label">计价单位</label>
                        <input type="text" class="form-control" id="unit" name="unit" required>
                    </div>
                    <div class="mb-3">
                        <label for="price" class="form-label">单价</label>
                        <input type="number" step="0.01" class="form-control" id="price" name="price" required>
                    </div>
                    <div class="mb-3">
                        <label for="description" class="form-label">工序描述</label>
                        <textarea class="form-control" id="description" name="description" rows="3" required></textarea>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-primary">保存</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>